home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_11.lha
/
6_11
/
tst.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
2KB
|
78 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <stream.h>
include <string.h>
include <values.h>
include <arbint.h>
oid testdiv(const arbint& A, const arbint& B)
arbint quot = A / B;
cout << A << " / " << B << " = " << quot << "\n";d}
oid testmod(const arbint& A, const arbint& B)
arbint rem = A % B;
cout << A << " % " << B << " = " << rem << "\n";d}
oid testdivmod(const arbint& A, const arbint& B)
arbint quot, rem;
dodivmod(A, B, quot, rem);
cout << A << " / " << B << " = " << quot << "\n";
cout << A << " % " << B << " = " << rem << "\n";
oid testmul(const arbint& A, const arbint& B)
arbint prod = A * B;
cout << A << " * " << B << " = " << prod << "\n";d}
oid testadd(const arbint& A, const arbint& B)
arbint sum = A + B;
cout << A << " + " << B << " = " << sum << "\n";
oid testsub(const arbint& A, const arbint& B)
arbint diff = A - B;
cout << A << " - " << B << " = " << diff << "\n";d}
oid testneg(const arbint& A)
arbint neg = -A;
cout << " 0, 0 - " << A << " = " << neg << "\n";d}
oid testpos(const arbint& A)
arbint pos = +A;
cout << " 0, 0 + " << A << " = " << pos << "\n";d}
nline int eq(char*s1, char*s2)
return (strcmp(s1, s2) == 0);
ain()
arbint x, y;
char op[100];
while (cin >> x >> op >> y)
{
if (eq(op, "+")) testadd(x, y);
else if (eq(op, "-")) testsub(x, y);
else if (eq(op, "*")) testmul(x, y);
else if (eq(op, "/")) testdiv(x, y);
else if (eq(op, "%")) testmod(x, y);
else if (eq(op, "/%")) testdivmod(x, y);
else if (eq(op, "--")) testneg(x);
else if (eq(op, "++")) testpos(x);
else cout << "unknown operator\n";
}
return 0;